package tspda

import glory.xxd.Utils
import tsCIM.ResultCode
import tsCIM.modelForInterface.Header
import tsCIM.modelForInterface.RequestModel
import tsCIM.modelForInterface.ResultModel
import tsCIM.modelForInterface.Return

class PDAProcessEndRequestController {

    def commentService

    def index() {
        def result = ResultModel.getResultModel()
        try {
            def USERNAME = params.USERNAME ?: ""
            def EQPID = params.EQPID ?: ""
            def LOTID = params.LOTID ?: ""
            def DONEQTY = params.DONEQTY ?: ""
            def JOBQTY = params.JOBQTY ?: ""
            def DEFECTSUM = params.DEFECTSUM ?: ""
            def QualifiedQty = params.QualifiedQty ?: ""

            def MACHINENAME = params.MACHINENAME ?: ""

            def body = [EQPID: EQPID, USERNAME: USERNAME, LOTID: LOTID, DONEQTY: DONEQTY, JOBQTY: JOBQTY, DEFECTSUM: DEFECTSUM, QualifiedQty: QualifiedQty]
            Header header = new Header(TRANSACTIONID: Utils.getUUID(), MESSAGENAME: "PDAProcessEndRequest", MACHINENAME: MACHINENAME)
            Return aReturn = new Return()
            RequestModel requestModel = new RequestModel(header: header, body: body, aReturn: aReturn)
//            result = commentService.getJsonByTopic2Queue(requestModel,"sendmqname","returnmqname",true,responseXml)
            result = commentService.getJsonByTopic2Queue(requestModel, "jms.topic.PDA.TO.CIM", "jms.queue.CIM.PDA.Send", false, false)
        } catch (Exception e) {
            result.put(ResultModel.ServerErrorFlag, true)
            result.put(ResultModel.Code, ResultCode.SERVER_INTERFACE_ERROR.code)
            result.put(ResultModel.Msg, ResultCode.SERVER_INTERFACE_ERROR.msg)
            result.put(ResultModel.Data, e.getMessage())
        } finally {
            render Utils.getFormatString(result)
        }
    }

    def responseXml = """
<MESSAGE>
<HEADER>
  <TRANSACTIONID>7d280c96-8d69-45a0-91da-be39659f674d</TRANSACTIONID>
  <MESSAGENAME>PDAMessageResponse</MESSAGENAME>
  <MACHINENAME>WM-2112</MACHINENAME>
  <WORKNO>1</WORKNO>
  <EVENTUSER>CIM</EVENTUSER>
  <EVENTTIME>2019-03-14 16:48:58.343</EVENTTIME>
</HEADER>
<BODY>
  <EQPID>DB-447</EQPID>
  <MESSAGETYPE>Info</MESSAGETYPE>
</BODY>
<RETURN>
  <RETURNCODE>0</RETURNCODE>
  <RETURNMESSAGE>结束作业成功</RETURNMESSAGE>
</RETURN>
</MESSAGE>
"""
}
